package com.etc.controller;

import com.etc.dto.Result;
import com.etc.entity.Inhospital;
import com.etc.service.InhospitalService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/inhospital")
public class InhospitalController {
    @Autowired
    private InhospitalService inhospitalService;
    @GetMapping("/1")
    public Result getInHospital(@RequestParam String inhospitalId){
        Result result = new Result();
        Inhospital inhospital =inhospitalService.getInhospital(inhospitalId);
        if(inhospital!=null){
            result.ok(inhospital);
        }else {
            result.fail(0,"数据有误");
        }
        return result;
    }
    @GetMapping
    public Result getInHospitalList(String condition, @RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        Result result = new Result();

        PageInfo<Inhospital> inhospitalList = inhospitalService.getInhospitalListByPage(condition, pageNum, pageSize);
        if (!inhospitalList.getList().isEmpty()) {
            result.ok(inhospitalList);
        } else {
            result.ok(inhospitalList).setMessage("没有相关数据");
        }
        return result;
    }

    //    添加住院信息
    @PostMapping
    public Result addInHospital(@RequestParam String patientName, @RequestParam String doctorName, @RequestParam String roomName,
                                @RequestParam String inTime) {
        Result result = new Result();
        int n=inhospitalService.addInhospital(patientName, doctorName,roomName,inTime);
        if(n>0){
            result.ok(true);
        }else {
            result.fail(0,"添加失败");
        }
        return result;
    }
    //修改住院信息
    @PostMapping("/update")
    public Result updateInHospital(@RequestParam String inhospitalId,@RequestParam String patientName, @RequestParam String doctorName, @RequestParam String roomName,
                                    @RequestParam String inTime,String outTime){

        Result result = new Result();
        int n=inhospitalService.updateInhospital(inhospitalId,patientName, doctorName,roomName,inTime,outTime);
        if(n>0){
            result.ok(true);
        }else {
            result.fail(0,"修改失败");
        }
        return result;
    }

}
